package org.tong.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.tong.feign.FeignProviderService;

@RestController
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/echo/{msg}")
    public String echo(@PathVariable(name = "msg") String msg) {
        return restTemplate.getForObject("http://service-provider/echo/" + msg, String.class);
    }

    @Autowired
    private FeignProviderService feignService;

    @RequestMapping("/echo/feign/{msg}")
    public String echoFeign(@PathVariable(name = "msg") String msg) {
        return feignService.echo(msg);
    }

}
